function creardatatable() {

    
	Context.StatusFormatter = function(cell, row, col, data){
        var combo = Context.VigenciaCatalog;
        for (var i = 0; i < combo.length; i++) {
            if (data == combo[i].value) {
                cell.innerHTML = combo[i].label;
                return;
            }
        }
    };
    

	var checkFmt = function(cell, row, col, data){
        var checked =data;
        if (checked == 'true' || checked == true) {
            cell.innerHTML = '<div align="center"><input type="checkbox" name="ignorame" checked="checked" ></input></div>';
        } else {
            cell.innerHTML = '<div align="center"><input type="checkbox" name="ignorame" ></input></div>';
        }
    };
    
	var myColumnDefs = [ {
		key : "clave",
		label : "ID"
	},{
		key : "desc",
		label : "PAIS"
	}, {
		label:"TIPO TRANSACCION", 
		children:[{
			key : "export",
			label : "EXPORTACION",
			formatter: checkFmt
		}, {
			key : "import",
			label : "IMPORTACION",
			formatter: checkFmt			
		}]
	}, {
		label:"TIPO CERTIFICADO", 
		children:[ {
			key : "fito",
			label : "FITOSANITARIO",
			formatter: checkFmt
		}, {
			key : "zoo",
			label : "ZOOSANITARIO",
			formatter: checkFmt
		}, {
			key : "acui",
			label : "ACUICOLA",
			formatter: checkFmt
		}]
	}];

	try {
		var config = {};
		config.URL = Context.Parametros;
		config.FIELDS = [ "clave", "desc", "export", "import", "fito", "zoo", "acui" ];
		config.COLUMNS = myColumnDefs;
		config.DATATABLE_DIV = "datatable";
		config.PAGINATOR_DIV = "paginator";
		config.TOTAL_REGISTROS_DIV = "totalregistros";
		config.ROW_PER_PAGE = 10;

		Context.table = new Z.Table(config);
		myDataTable = Context.table.getDatatable();
		
	} catch (e) {
		alert(e);
	}
}

function creardatatablemercancias() {

	var checkFmt = function(cell, row, col, data){
        var checked =data;
        if (checked == 'true' || checked == true) {
            cell.innerHTML = '<div align="center"><input type="checkbox" name="ignorame" checked="checked" ></input></div>';
        } else {
            cell.innerHTML = '<div align="center"><input type="checkbox" name="ignorame" ></input></div>';
        }
    };
    
	var myColumnDefs = [ {
		key : "id",
		label : "*",
		formatter : checkFmt,
		width : "20"
	},{
		key : "id",
		label : "ID"
	},{
		key : "desc",
		label : "NOMBRE COMUN"
	}, {
		key : "scien",
		label : "NOMBRE CIENTIFICO"
	
	}];

	try {
		var config = {};
		config.URL = Context.Mercancias;
		config.FIELDS = [ "id", "desc", "scien" ];
		config.COLUMNS = myColumnDefs;
		config.DATATABLE_DIV = "datatableD";
		config.PAGINATOR_DIV = "paginatorD";
		config.TOTAL_REGISTROS_DIV = "totalregistrosD";
		config.ROW_PER_PAGE = 10;

		Context.tableD = new Z.Table(config);
		myDataTableD = Context.table.getDatatable();
		
	} catch (e) {
		alert(e);
	}
}





function valida() {
	try {
		var f = document.getElementById("detalleForm");
		var callback = new Z.JsonCall();
		callback.exito = function(data) {
		};
		callback.fallo = function(messages) {
		};
		Z.ShowWait();
		Y.util.Connect.setForm(f);
		var request = Y.util.Connect.asyncRequest('POST', Context.Guarda,
				callback);

	} catch (e) {
		alert("valida: " + e + e.description);
	}
};



function creardialogo() {
	Context.dialog1 = new Y.widget.Dialog("dialog1", {
		width : "80em",
		height : "45em",
		fixedcenter : true,
		visible : false,
		constraintoviewport : false,
		modal : true,
		zindex : 5,
		buttons : [ {
			text : "Aceptar",
			handler : function(){
				Context.dialog1.hide();
			},
			isDefault : true
		}, {
			text : "Cancelar",
			handler : function(){
				Context.dialog1.hide();
			}
		} ]
	});
	var kw = new Y.util.KeyListener(document, {
		keys : 27
	}, {
		fn : Context.dialog1.hide,
		scope : Context.dialog1,
		correctScope : true
	});
	kw.enable();
	Context.dialog1.render(document.body);
	
	
	Context.dialog2 = new Y.widget.Dialog("dialog2", {
		width : "80em",
		height : "45em",
		fixedcenter : true,
		visible : false,
		constraintoviewport : false,
		modal : true,
		zindex : 5,
		buttons : [ {
			text : "Aceptar",
			handler : function(){
				Context.dialog2.hide();
			},
			isDefault : true
		} ]
	});
	var kw = new Y.util.KeyListener(document, {
		keys : 27
	}, {
		fn : Context.dialog2.hide,
		scope : Context.dialog2,
		correctScope : true
	});
	kw.enable();
	Context.dialog2.render(document.body);
	
	
}



function crearbotones() {

	
	new Y.widget.Button("guardabutton", {
		onclick : {
			fn : function() {
				valida() ;
			}
		}
	});

};

Y.util.Event.onDOMReady(function() {
	try {
		creardatatable();
		creardatatablemercancias();
		creardialogo();
		crearbotones();
		
		Context.table.update();
		Context.tableD.update();
	} catch (e) {
		alert(e);
	}
});
